﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CSP.DataAccess;
using CSP.Dao.CommonDao;
using CSP.Dao.IObjectDaos.CSP;
using CSP.Model.CSP;

namespace CSP.Dao.ObjectDaos.CSP
{
    public class ServiceInfoServiceTypeRelDao : CSPCommonDao, IServiceInfoServiceTypeRelDao
    {
        public ServiceInfoServiceTypeRelDao(CSPContext context, bool isTransaction = false)
            : base(context, isTransaction)
        { }

        public List<int> GetServiceIdsByServiceTypeIdAndServiceIds(int serviceTypeId, List<int> serviceIds)
        {
            List<int> result = new List<int>();
            IQueryable<int> ids = null;
            if (serviceIds != null && serviceIds.Count != 0)
            {
                ids = _context.ServiceInfoServiceTypeRels.Where(r => r.ServiceTypeId == serviceTypeId && serviceIds.Contains(r.ServiceInfoId)).Select(r => r.ServiceInfoId);
            }
            else
            {
                ids = _context.ServiceInfoServiceTypeRels.Where(r => r.ServiceTypeId == serviceTypeId).Select(r => r.ServiceInfoId);
            }

            if (ids.Count() != 0)
            {
                result = ids.ToList();
            }

            return result;
        }
    }
}
